﻿package model.drawPanel.entitys;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wb.swt.SWTResourceManager;


public class Rectangle extends Entity {

  /**
	 * 
	 */
	private static final long serialVersionUID = 101250104L;
	public int fillColor;
	public Rectangle(int id, Color color, int width, int style, int x1, int y1,
			int x2, int y2) {
		super(id, color, width, style, x1, y1, x2, y2);
		// TODO Auto-generated constructor stub
	}
@Override
public void draw(Display display, GC gc) {
	if(color ==null){
		super.initeColor();
	}
	if(isChoosed){
		gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
		gc.setLineWidth(3);
		gc.setLineStyle(SWT.LINE_SOLID);
		gc.drawOval(Math.min(x1, x2)-width/2-12, Math.min(y1, y2)-width/2-12, 12, 12);
		gc.drawOval(Math.max(x1, x2)+width/2, Math.min(y1, y2)-width/2-12, 12, 12);
		gc.drawOval(Math.min(x1, x2)-width/2-12, Math.max(y1, y2) +width/2, 12, 12);
		gc.drawOval(Math.max(x1, x2) + width/2, Math.max(y1, y2)+width/2, 12, 12);
		gc.setAlpha(128);
		gc.setForeground(color);
		gc.setLineStyle(style);
		gc.setLineWidth(width);
		gc.drawRectangle(Math.min(x1 ,x2),Math.min(y1, y2) , Math.abs(x2 - x1), Math.abs(y2 - y1));
		gc.setAlpha(255);
	}else {
		gc.setForeground(color);
		gc.setLineStyle(style);
		gc.setLineWidth(width);
		gc.drawRectangle(Math.min(x1 ,x2),Math.min(y1, y2) , Math.abs(x2 - x1), Math.abs(y2 - y1));
	}
	
	
	
}
//
@Override
public String isFocused(int x, int y) {
	super.isFocused(x, y);
	if(isChoosed){
		if(distance(x1-width/2-6, y1-width/2-6,x,y) <= 6){
			return "zoomleftup";
		}
		if(distance(x1-width/2-6, y2 +width/2 +6,x,y) <= 6){
			return"zoomleftdown";
		}
		if(distance(x2+width/2 + 6, y1-width/2-6, x,y) <= 6 ){
			return"zoomrightup";
		}
		if(distance(x2 + width/2 +6, y2+width/2 +6,x,y) <= 6){
			return"zoomrightdown";
		}
	}else if( x >= x1-width/2.0 && x <= x2+width/2.0 && y >= y1-width/2.0 && y <= y2 +width/2.0){//大矩形内
		if( x >= x1+width/2.0 && x <= x2 -width/2.0 && y >= y1 +width/2.0 && y <=y2 -width/2.0){//小矩形内
			return "noEnter";
		}
		return "entity";//大矩形内小矩形外
	}
	return "noEnter";
}

}